package com.chen.cart.controller;

import cn.hutool.log.Log;
import com.chen.cart.service.CartService;
import com.chen.model.entity.h5.CartInfo;
import com.chen.model.vo.common.Result;
import com.chen.model.vo.common.ResultCodeEnum;
import org.simpleframework.xml.Path;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author cgj
 * @date 4/22/25 7:57 PM
 */
@RestController
@RequestMapping("/api/order/cart/auth")
public class CartController {
    @Autowired
    private CartService cartService;

    /**
     * 删除用户选中的购物车项目
     * /api/order/cart/auth/deleteChecked
     */
    @DeleteMapping("/deleteChecked")
    public void deleteChecked(){
        cartService.deleteChecked();
    }
    /**
     * /api/order/cart/auth/getAllChecked
     * 获取选中的全部购物车项的列表
     */
    @GetMapping("/getAllChecked")
    public List<CartInfo> getAllChecked(){
        return cartService.getAllChecked();
    }

    /**
     * 清空购物车
     * http://localhost:8500/api/order/cart/auth/clearCart
     */
    @GetMapping("/clearCart")
    public Result clearCart(){
        cartService.clearCart();
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     *  购物车商品全部选中,或者不选中
     * http://localhost:8500/api/order/cart/auth/allCheckCart/1
     */
    @GetMapping("allCheckCart/{status}")
    public Result allCheckCart(@PathVariable Integer status){
        cartService.allCheckCart(status);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }

    /**
     * 修改商品选中状态
     *
     http://localhost:8500/api/order/cart/auth/checkCart/2/0
     */
    @GetMapping("checkCart/{skuId}/{checkStatus}")
    public Result checkCart(@PathVariable long skuId,
                            @PathVariable Integer checkStatus){
        cartService.checkCart(skuId,checkStatus);
        return  Result.build(null,ResultCodeEnum.SUCCESS);
    }
    /**
     *
     http://localhost:8500/api/order/cart/auth/deleteCart/3
     * 删除购物车项
     */
     @DeleteMapping("deleteCart/{skuId}")
     public Result deleteCart(@PathVariable Long skuId){
         cartService.deleteCart(skuId);
         return  Result.build(null,ResultCodeEnum.SUCCESS);
     }
    /**
     * 当前用户购物车列表查询
     * http://localhost:8500/api/order/cart/auth/cartList
     */
     @GetMapping("/cartList")
     public Result<List<CartInfo>> cartList(){
        List<CartInfo> cartInfoList =cartService.cartList();
         return Result.build(cartInfoList,ResultCodeEnum.SUCCESS);
    }

    /**
     *  api/order/cart/auth/addToCart/{skuId}/{skuNum}
     * 加入购物车
     * @param skuId
     * @param skuNum
     * @return
     */
    @GetMapping("addToCart/{skuId}/{skuNum}")
    public Result addToCart(@PathVariable Long skuId,
                            @PathVariable Integer skuNum){
        cartService.addToCart(skuId,skuNum);
        return  Result.build(null, ResultCodeEnum.SUCCESS);
    }
}
